/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
 * Description: 
 * Author: g00421808
 * Create: 6/28/2022
 * Notes: 
 */

#ifndef JSBIND_GETTER_BINDER_H
#define JSBIND_GETTER_BINDER_H
#include "binder.h"

namespace Jsb {

/**
 * @brief: 类属性访问器Get函数类型Binder，定义所有类属性访问器Get函数回调类型为：R (C::*)()的回调Binder
 */
template <typename BinderType, typename C, typename M, typename R>
class GetterBinder : public TemplatedBinder<BinderType, M, R> {
public:
    // | static |
    /**
     * @brief: 根据ClassType::Method注册时的Invoker Id获取调用器对象进行函数实体调用
     * @param: receiver: 类实例对象
     *         binderInfo: invoker索引ID
     * @Note: 注意入参必须是引用，如果传值前是指针，需要解指针
     */
    static R InnerWrapper(C& receiver, Jsb::BindInfo* bindInfo) {
        const auto& invokerInfo = BinderType::GetInvoker(bindInfo->getterNumber);
        return Invoker<R (*)()>::InvokeMethod(receiver, invokerInfo.invoker);
    }

    static constexpr auto type = Binder::Type::Getter;

};
} // namespace Jsb
#endif //JSBIND_GETTER_BINDER_H
